package cn.iocoder.yudao.module.agent.convert.brokerageuser;

import java.util.*;

import cn.iocoder.yudao.framework.common.pojo.PageResult;

import cn.iocoder.yudao.module.agent.base.MemberRespVO;
import cn.iocoder.yudao.module.agent.controller.admin.user.vo.AgentUserRespVO;
import cn.iocoder.yudao.module.agent.controller.admin.withdrawaccount.vo.AgentWithdrawAccountRespVO;
import cn.iocoder.yudao.module.agent.convert.base.AgentConvert;
import cn.iocoder.yudao.module.agent.convert.withdrawaccount.AgentWithdrawAccountConvert;
import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import cn.iocoder.yudao.module.agent.controller.admin.brokerageuser.vo.*;
import cn.iocoder.yudao.module.agent.dal.dataobject.brokerageuser.AgentBrokerageUserDO;

/**
 * 代理人分销用户 Convert
 *
 * @author 曹建伟
 */
@Mapper
public interface AgentBrokerageUserConvert {

    AgentBrokerageUserConvert INSTANCE = Mappers.getMapper(AgentBrokerageUserConvert.class);

    AgentBrokerageUserDO convert(AgentBrokerageUserCreateReqVO bean);

    AgentBrokerageUserDO convert(AgentBrokerageUserUpdateReqVO bean);

    AgentBrokerageUserRespVO convert(AgentBrokerageUserDO bean);

    List<AgentBrokerageUserRespVO> convertList(List<AgentBrokerageUserDO> list);

    PageResult<AgentBrokerageUserRespVO> convertPage(PageResult<AgentBrokerageUserDO> page);

    List<AgentBrokerageUserExcelVO> convertList02(List<AgentBrokerageUserDO> list);

    default AgentBrokerageUserCreateReqVO convert(Long agentUserId, Long brokerageUserId){
        AgentBrokerageUserCreateReqVO createReqVO = new AgentBrokerageUserCreateReqVO();
        createReqVO.setAgentUserId(agentUserId);
        createReqVO.setUserId(brokerageUserId);

        return createReqVO;
    }

    default AgentBrokerageUserRespVO convert(AgentBrokerageUserDO bean, MemberRespVO memberRespVO, MemberRespVO agentMemberRespVO){
        if(bean == null){
            return null;
        }

        AgentBrokerageUserRespVO agentBrokerageUserRespVO = new AgentBrokerageUserRespVO();
        agentBrokerageUserRespVO.setUserId(bean.getUserId());
        agentBrokerageUserRespVO.setAgentUserId(bean.getAgentUserId());
        agentBrokerageUserRespVO.setCreateTime(bean.getCreateTime());
        agentBrokerageUserRespVO.setId(bean.getId());
        agentBrokerageUserRespVO.setOrderCount(bean.getOrderCount());
        agentBrokerageUserRespVO.setTotalPrice(bean.getTotalPrice());

        agentBrokerageUserRespVO.setMember(memberRespVO);
        agentBrokerageUserRespVO.setAgentMember(agentMemberRespVO);

        return agentBrokerageUserRespVO;
    }

    default List<AgentBrokerageUserRespVO> convertList(List<AgentBrokerageUserDO> agentBrokerageUserDOList, Map<Long, MemberUserRespDTO> memberMap, Map<Long, MemberUserRespDTO> agentMemberMap){
        List<AgentBrokerageUserRespVO> list = new ArrayList<>();
        agentBrokerageUserDOList.forEach(agentBrokerageUserDO -> {
            MemberRespVO memberRespVO = AgentConvert.INSTANCE.covnertMember(memberMap.get(agentBrokerageUserDO.getUserId()));
            MemberRespVO agentMemberRespVO = AgentConvert.INSTANCE.covnertMember(agentMemberMap.get(agentBrokerageUserDO.getAgentUserId()));
            list.add(convert(agentBrokerageUserDO, memberRespVO, agentMemberRespVO));
        });

        return list;
    }

    default PageResult<AgentBrokerageUserRespVO> convertPage(PageResult<AgentBrokerageUserDO> page, Map<Long, MemberUserRespDTO> memberMap, Map<Long, MemberUserRespDTO> agentMemberMap){
        if ( page == null ) {
            return null;
        }

        PageResult<AgentBrokerageUserRespVO> pageResult = new PageResult<AgentBrokerageUserRespVO>();
        List<AgentBrokerageUserRespVO> list = convertList(page.getList(), memberMap, agentMemberMap);

        pageResult.setList(list);
        pageResult.setTotal(page.getTotal());

        return pageResult;
    }
}
